// pages/address/address.js
const app = getApp()
var service = require('../../util/service')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addressList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAddresss();
  },
  getAddresss(){
    var user = app.userInfo;
    var that = this;
    service.AJAX(`smc/base/SystemReceiveAddress/listSystemReceiveAddress.json`, { "$userId": user.buyId }, res => {
      that.setData({
        addressList: res
      });
    }, err => { }, "POST");
  },
  delAddress(e){
    var id = e.target.dataset.id;
    var that = this;
    service.AJAX(`smc/base/SystemReceiveAddress/delSystemReceiveAddress.do`, { "id": id }, res => {
      wx.showToast({
        title: "删除成功",
        duration: 1000,
        mask: true
      })
      that.getAddresss();
    }, err => { }, "POST");
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})